package prj.stars;

import java.text.DecimalFormat;
 
/**
 * A group member is a student from a specified group. For each student some information is kept: student name, stars
 * representing student activity in class, its presence in class, its grade and maybe others like results of tests/
 * homework. It is comparable, so that a list of students is ordered alphabetically.
 * 
 * @author Andreea-Cristina Hodea
 *
 */

public class GroupMember implements Comparable<GroupMember>{

	private String student;
	private int stars;
	private int presence;
	private float grade;
	
	public GroupMember(String studentName) {
		student = studentName;
		stars = 0;
		presence = 0;
		setGrade();
	}
	
	public GroupMember(String studentName, int stars, int presence) {
		student = studentName;
		this.stars = stars;
		this.presence = presence;
		setGrade();
	}
	
	public String getStudent() {
		return student;
	}
	public void setStudent(String student) {
		this.student = student;
	}
	public int getStars() {
		return stars;
	}
	public void setStars(int stars) {
		this.stars = stars;
		setGrade();
	}
	public int getPresence() {
		return presence;
	}
	public void setPresence(int presence) {
		this.presence = presence;
		setGrade();
	}	
	public float getGrade() {
		return grade;
	}
	/* 10 stars represent  5 points out of 10 points, while presence 14 represents the rest of 5 points */
	private void setGrade(){
		grade = (float)stars / 2 + (float)presence * 5 /14;
	}

	public String toString(){
		return student + ": " + stars + ", " + presence + ", " + (new DecimalFormat("#.##").format(grade));
	}
	
	public boolean equals(Object o) {
		if (o instanceof GroupMember) {
			return ((GroupMember) o).getStudent().equals(student);
		}
		return false;
	}
	
	public int HashCode() {
		return student.hashCode();
	}
	
	public int compareTo(GroupMember student) {
		return this.student.compareTo(student.getStudent());
	}
}
